package com.erp.warehouse.clouderp_warehouse.controller;

import com.erp.warehouse.clouderp_warehouse.service.inventory.InventoryBatchService;
import com.erp.warehouse.clouderp_warehouse.service.inventory.InventorySerialService;
import com.erp.warehouse.clouderp_warehouse.service.inventory.InventoryService;
import org.comple.erp.pojo.ResultStatus;
import org.comple.erp.pojo.warehouse.Inventory;
import org.comple.erp.remote.warehouse.InventoryRemote;
import org.comple.erp.utils.AjaxResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

/**
 * 2025/11/11 16:09
 * author: 向远洋
 */
@RestController
@RequestMapping("/inventory")
public class InventoryController implements InventoryRemote {
    @Autowired
    InventoryService inventoryService;
    @Autowired
    InventoryBatchService batchService;
    @Autowired
    InventorySerialService serialService;

    @Value("${auth.staffId}")
    String staffId;
    @Value("${auth.companyId}")
    String companyId;

    @Override
    @PostMapping("/stock")
    public List<Inventory> getAllStock(@RequestBody Map<String, Object> params) {
//        return AjaxResult.back(ResultStatus.SUCCESS, "获取商品库存信息成功！")
//                .add("stockList", inventoryService.getAllStockList(params));
        return inventoryService.getAllStockList(params);
    }

    @Override
    @PostMapping("/init")
    public AjaxResult initGoodsStock(@RequestBody Map<String, Object> map) {
        if(inventoryService.initGoodsStock(map))
            return AjaxResult.back(ResultStatus.SUCCESS, "初始化商品库存信息成功！");
        throw new RuntimeException("初始化商品库存信息失败!");
    }

    @PostMapping("/batchList")
    public AjaxResult getBatchList(@RequestBody Map<String, Object> params) {
        params.put("companyId", companyId);
        return AjaxResult.back(ResultStatus.SUCCESS, "获取商品批次列表成功！")
                .add("batchList", batchService.getBatchList(params));
    }

    @PostMapping("/serialList")
    public AjaxResult getSerialList(@RequestBody Map<String, Object> params) {
        params.put("companyId", companyId);
        return AjaxResult.back(ResultStatus.SUCCESS, "获取商品序列号列表成功！")
                .add("serialList", serialService.getSerailList(params));
    }
}
